﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DFGK.Service
{
    public class PackService : BaseService, IPackService
    {
        private readonly IPackRepository _packRepository;
        private readonly IUnitOfWork _unitOfWork;
        public PackService(IMapper mapper, IPackRepository _packRepository, IUnitOfWork _unitOfWork) : base(mapper)
        {
            this._packRepository = _packRepository;
            this._unitOfWork = _unitOfWork;
        }

        public bool AddPack(Pack m, out string message)
        {
            message = string.Empty;
            var pobj = _packRepository.QueryIsEntityWhere(x => x.Code == m.Code);
            if (pobj != null)
            {
                message = "编码已存在！";
                return false;
            }
            _packRepository.AddEntity(m);
            return _unitOfWork.SaveChangesEntity();
        }

        public List<Pack> GetPackList(int pageIndex, int pageSize, out int totalCount)
        {
            var plist = _packRepository.GetEntityAlls();

            var list = _packRepository.GetEntityAlls(plist, pageIndex, pageSize, out totalCount, x => x.CreateDate, false);
            return list.ToList();
        }
    }
}
